home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / bbs_util / bsrc_260.zip / SRC.ZIP / FTSC.C < prev    next >
C/C++ Source or Header  |  1996-02-20  |  21KB  |  842 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software, Co.                       */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          Freely Available<tm> Software.                 */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*              (C) Copyright 1987-96, Bit Bucket Software Co.              */
  11. /*                                                                          */
  12. /*                 This module was written by Bob Hartman                   */
  13. /*                                                                          */
  14. /*                 BinkleyTerm FTSC Mail Session Routines                   */
  15. /*                                                                          */
  16. /*                                                                          */
  17. /*    For complete  details  of the licensing restrictions, please refer    */
  18. /*    to the License  agreement,  which  is published in its entirety in    */
  19. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.260.    */
  20. /*                                                                          */
  21. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  22. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  23. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  24. /*    NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  25. /*    SOFTWARE CO.  AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  26. /*    SHOULD YOU  PROCEED TO USE THIS FILE  WITHOUT HAVING  ACCEPTED THE    */
  27. /*    TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  28. /*    AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.      */
  29. /*                                                                          */
  30. /*                                                                          */
  31. /* You can contact Bit Bucket Software Co. at any one of the following      */
  32. /* addresses:                                                               */
  33. /*                                                                          */
  34. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:343/491             */
  35. /* P.O. Box 460398                AlterNet 7:42/1491                        */
  36. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  37. /*                                Internet f491.n343.z1.fidonet.org         */
  38. /*                                                                          */
  39. /* Please feel free to contact us at any time to share your comments about  */
  40. /* our software and/or licensing policies.                                  */
  41. /*                                                                          */
  42. /*--------------------------------------------------------------------------*/
  43.  
  44. /* Include this file before any other includes or defines! */
  45.  
  46. #include "includes.h"
  47.  
  48. #define rb_plus "r+b"
  49.  
  50. static int FTSC_callback (char *);
  51. static int FTSC_time (long);
  52. static int LOCALFUNC FTSC_sendmail (void);
  53. static int LOCALFUNC FTSC_recvmail (int);
  54.  
  55. #define NUM_FLAGS 4
  56.  
  57. void 
  58. FTSC_sender (int wz)
  59. {
  60.     int j;
  61.     char junkbuff[128];
  62.     long t1;
  63.  
  64.     XON_DISABLE ();
  65.     first_block = 0;
  66.  
  67.     if (!wz)
  68.     {
  69.         first_block = 1;
  70.         status_line (MSG_TXT (M_SEND_FALLBACK));
  71.         who_is_he = 0;
  72.         (void) sprintf (junkbuff, "*%s (%s)",
  73.             newnodedes.SystemName,
  74.             Full_Addr_Str (&remote_addr));
  75.         status_line (junkbuff);
  76.     }
  77.  
  78.     Netmail_Session = 1;
  79.  
  80.     (void) FTSC_sendmail ();
  81.     t1 = timerset (4500);
  82.  
  83.     /* See what the receiver would like us to do */
  84.  
  85.     while ((!timeup (t1)) && CARRIER)
  86.     {
  87.         if ((j = PEEKBYTE ()) >= 0)
  88.         {
  89.             switch (j)
  90.             {
  91.             case TSYNC:
  92.                 CLEAR_INBOUND ();
  93.                 if (FTSC_recvmail (1))
  94.                     goto get_out;
  95.                 t1 = timerset (4500);
  96.                 break;
  97.  
  98.             case SYN:
  99.                 CLEAR_INBOUND ();
  100.                 if (on_our_nickel)
  101.                     (void) SEA_recvreq ();
  102.                 else
  103.                 {
  104.                     SENDBYTE (CAN);
  105.                     status_line (MSG_TXT (M_REFUSING_IN_FREQ));
  106.                 }
  107.                 t1 = timerset (4500);
  108.                 break;
  109.  
  110.             case ENQ:
  111.                 CLEAR_INBOUND ();
  112.                 SEA_sendreq ();
  113.                 goto get_out;
  114.  
  115.             case NAK:
  116.             case 'C':
  117.                 CLEAR_INBOUND ();
  118.                 SENDBYTE (EOT);
  119.                 t1 = timerset (4500);
  120.                 break;
  121.  
  122.             default:
  123.                 CLEAR_INBOUND ();
  124.                 SENDBYTE (SUB);
  125.                 break;
  126.             }
  127.         }
  128.         else
  129.         {
  130.             time_release ();
  131.         }
  132.     }
  133.  
  134.     if (!CARRIER)
  135.     {
  136.         status_line (MSG_TXT (M_NO_CARRIER));
  137.         CLEAR_INBOUND ();
  138.         first_block = 0;
  139.         return;
  140.     }
  141.  
  142.     if (timeup (t1))
  143.     {
  144.         (void) FTSC_recvmail (1);
  145.         status_line (MSG_TXT (M_TOO_LONG));
  146.     }
  147.  
  148. get_out:
  149.  
  150.     first_block = 0;
  151.     t1 = timerset (100);
  152.     while (!timeup (t1))
  153.         time_release ();
  154.     if (!wz)
  155.         status_line (MSG_TXT (M_0001_END));
  156. }
  157.  
  158. int 
  159. FTSC_receiver (int wz)
  160. {
  161.     char fname[64];
  162.     int havemail, done, np;
  163.     unsigned int i;
  164.     long t1, t2;
  165.     struct stat buf;
  166.     char *HoldName;
  167.     struct FILEINFO dta =
  168.     {0};
  169.     ADDR tmp;
  170.  
  171.     first_block = 0;
  172.     XON_DISABLE ();
  173.  
  174.     if (!wz)
  175.     {
  176.         first_block = 1;
  177.         status_line (MSG_TXT (M_RECV_FALLBACK));
  178.         who_is_he = 1;
  179.     }
  180.  
  181.     Netmail_Session = 1;
  182.  
  183.     CLEAR_INBOUND ();
  184.  
  185.     /* Save the state of pickup for now */
  186.  
  187.     done = no_pickup;
  188.     no_pickup = 0;
  189.     if (FTSC_recvmail (0))
  190.     {
  191.         /* Restore the state of pickup */
  192.  
  193.         no_pickup = done;
  194.         if (!wz)
  195.             status_line (MSG_TXT (M_0001_END));
  196.         first_block = 0;
  197.         return (1);
  198.     }
  199.  
  200.     /* Restore the state of pickup */
  201.  
  202.     no_pickup = done;
  203.  
  204.     remote_addr = called_addr;
  205.  
  206.     HoldName = HoldAreaNameMunge (&called_addr);
  207.  
  208.     /* Now see if we should send anything back to him */
  209.  
  210.     (void) sprintf (fname, "%s%s.?UT", HoldName, Hex_Addr_Str (&remote_addr));
  211.     havemail = !dfind (&dta, fname, 0);
  212.  
  213.     if (!havemail)
  214.     {
  215.         (void) sprintf (fname, "%s%s.?LO", HoldName, Hex_Addr_Str (&remote_addr));
  216.         havemail = !dfind (&dta, fname, 0);
  217.     }
  218.  
  219.     if (!havemail)
  220.     {
  221.         for (np = 0; np <= ALIAS_CNT; np++)
  222.         {
  223.             if (alias[np].Net == 0)
  224.                 break;
  225.             (void) sprintf (fname, "%s%s.REQ", CURRENT.sc_Inbound, Hex_Addr_Str (&(alias[np])));
  226.             havemail = !dfind (&dta, fname, 0);
  227.             if (havemail)
  228.                 break;
  229.         }
  230.     }
  231.  
  232.     if (!havemail)
  233.     {
  234.         status_line (MSG_TXT (M_NOTHING_TO_SEND), Full_Addr_Str (&remote_addr));
  235.     }
  236.     else
  237.     {
  238.         /* Release any resource involved in finding the mail */
  239.  
  240.         (void) dfind (&dta, NULL, 2);
  241.         status_line (MSG_TXT (M_GIVING_MAIL), Full_Addr_Str (&remote_addr));
  242.  
  243.         /* Send the TSYNC's until we get a C or NAK or CAN back */
  244.  
  245.         t1 = timerset (3000);    /* set 30 second timeout */
  246.         done = 0;
  247.         while (!timeup (t1) && CARRIER && !done)    /* till then or CD lost  */
  248.         {
  249.             SENDBYTE (TSYNC);
  250.  
  251.             t2 = timerset (300);
  252.             while (CARRIER && (!timeup (t2)) && !done)
  253.             {
  254.                 switch (TIMED_READ (0))
  255.                 {
  256.                 case 'C':
  257.                 case NAK:
  258.                     done = 1;
  259.                     (void) FTSC_sendmail ();
  260.                     break;
  261.  
  262.                 case CAN:
  263.                     done = 1;
  264.                     status_line (MSG_TXT (M_REFUSE_PICKUP), Full_Addr_Str (&remote_addr));
  265.                     break;
  266.  
  267.                 default:
  268.                     time_release ();
  269.                 }
  270.             }
  271.         }
  272.     }
  273.  
  274.     first_block = 0;
  275.  
  276.     if (wz)
  277.         return TRUE;            /* All done if this is WaZOO */
  278.  
  279.     /* Now see if we want to request anything */
  280.  
  281.     tmp = remote_addr;
  282.  
  283.     /* For a point, massage the address to get the right .REQ filename */
  284.  
  285.     if (tmp.Point != 0)
  286.     {
  287.         tmp.Node = tmp.Point;
  288.         tmp.Point = 0;
  289.         tmp.Net = (pvtnet > 0) ? (unsigned int) pvtnet : 0;
  290.     }
  291.  
  292.     (void) sprintf (fname, "%s%s.REQ", HoldName, Hex_Addr_Str (&tmp));
  293.     if (!stat (fname, &buf))
  294.     {
  295.         /* Send the SYN character and wait for an ENQ or CAN */
  296.  
  297.         t1 = timerset (3000);    /* set 30 second timeout */
  298.         done = 0;
  299.         while (!timeup (t1) && CARRIER && !done)    /* till then or CD lost  */
  300.         {
  301.             SENDBYTE (SYN);
  302.  
  303.             t2 = timerset (500);
  304.             while (CARRIER && (!timeup (t2)) && !done)
  305.             {
  306.                 i = (unsigned) TIMED_READ (0);
  307.  
  308.                 switch (i)
  309.                 {
  310.                 case ENQ:
  311.                     SEA_sendreq ();
  312.                     break;
  313.  
  314.                 case CAN:
  315.                     done = 1;
  316.                     break;
  317.  
  318.                 case 'C':
  319.                 case NAK:
  320.                     SENDBYTE (EOT);
  321.                     break;
  322.  
  323.                 case SUB:
  324.                     SENDBYTE (SYN);
  325.                     break;
  326.  
  327.                 default:
  328.                     time_release ();
  329.                 }
  330.             }
  331.         }
  332.     }
  333.  
  334.     /* Finally, can he request anything from us */
  335.  
  336.     if (!no_requests)
  337.         (void) SEA_recvreq ();
  338.  
  339.     status_line (MSG_TXT (M_0001_END));
  340.     return TRUE;
  341. }
  342.  
  343. static int LOCALFUNC 
  344. FTSC_sendmail ()
  345. {
  346.     FILE *fp;
  347.     char fname[80];
  348.     char s[80];
  349.     char *sptr;
  350.     char *HoldName;
  351.     int c;
  352.     int i;
  353.     int j = 0;
  354.     struct stat buf;
  355.     struct _pkthdr *tmppkt;
  356.     time_t t1;
  357.     struct tm *tm1;
  358.  
  359.     XON_DISABLE ();
  360.  
  361.     (void) n_getpassword (&called_addr);    /* Update "assumed" */
  362.  
  363.     sptr = s;
  364.  
  365.     /*--------------------------------------------------------------------*/
  366.     /* Send all waiting ?UT files (mail packets)                          */
  367.     /*--------------------------------------------------------------------*/
  368.  
  369.     *ext_flags = 'O';
  370.     HoldName = HoldAreaNameMunge (&called_addr);
  371.     for (c = 0; c < NUM_FLAGS; c++)
  372.     {
  373. #ifndef JACK_DECKER
  374.         if (caller && (ext_flags[c] == 'H'))
  375.             continue;
  376. #endif
  377.         (void) sprintf (fname,
  378.             "%s%s.%cUT",
  379.             HoldName, Hex_Addr_Str (&called_addr), ext_flags[c]);
  380.  
  381.         if (!stat (fname, &buf))
  382.             break;
  383.     }                            /* for */
  384.  
  385.     /*--- Build a dummy PKT file name */
  386.  
  387.     invent_pkt_name (s);
  388.  
  389.     status_line (MSG_TXT (M_PACKET_MSG));
  390.  
  391.     if (c == NUM_FLAGS)
  392.     {
  393.         (void) sprintf (fname,
  394.             "%s%s.OUT",
  395.             HoldName, Hex_Addr_Str (&called_addr));
  396.         if ((fp = fopen (fname, write_binary)) == NULL)
  397.         {
  398.             (void) got_error (MSG_TXT (M_OPEN_MSG), fname);
  399.             return (1);
  400.         }
  401.         t1 = time (NULL);
  402.         tm1 = localtime (&t1);
  403.  
  404.         tmppkt = (struct _pkthdr *) calloc (1, sizeof (struct _pkthdr));
  405.  
  406.         if (tmppkt == NULL)
  407.         {
  408.             status_line (MSG_TXT (M_MEM_ERROR));
  409.             (void) fclose (fp);
  410.             return (1);
  411.         }
  412.         tmppkt->orig_node = (int) alias[assumed].Node;
  413.         tmppkt->dest_node = called_addr.Node;
  414.         tmppkt->ver = PKTVER;
  415.         tmppkt->orig_net = (int) alias[assumed].Net;
  416.         tmppkt->dest_net = called_addr.Net;
  417.         tmppkt->product = PRDCT_CODE;
  418.         if (n_getpassword (&called_addr) > 0)
  419.         {
  420.             if (remote_password != NULL)
  421.             {
  422.                 (void) strupr (remote_password);
  423.                 (void) strncpy ((char *) (tmppkt->password), remote_password, 8);
  424.             }
  425.         }
  426.         tmppkt->orig_zone = (int) alias[assumed].Zone;
  427.         tmppkt->dest_zone = called_addr.Zone;
  428.  
  429.         if (((called_addr.Domain != NULL)
  430.                 && (called_addr.Domain != alias[assumed].Domain)
  431.                 && (my_addr.Domain != NULL))
  432.             || (alias[assumed].Point != 0))
  433.         {
  434.             /* Make it a type 2.2 packet instead */
  435.             tmppkt->year = alias[assumed].Point;
  436.             tmppkt->month = called_addr.Point;
  437.             tmppkt->day = 0;
  438.             tmppkt->hour = 0;
  439.             tmppkt->minute = 0;
  440.             tmppkt->second = 0;
  441.             tmppkt->rate = 2;
  442.             if (alias[assumed].Domain != NULL)
  443.             {
  444.                 for (i = 0; domain_name[i] != NULL; i++)
  445.                 {
  446.                     if (domain_name[i] == alias[assumed].Domain)
  447.                     {
  448.                         break;
  449.                     }
  450.                 }
  451.                 if (i < 49)
  452.                 {
  453.                     (void) strncpy ((char *) tmppkt->B_fill2, domain_abbrev[i], 8);
  454.                 }
  455.             }
  456.  
  457.             for (i = 0; domain_name[i] != NULL; i++)
  458.             {
  459.                 if (domain_name[i] == called_addr.Domain)
  460.                 {
  461.                     break;
  462.                 }
  463.             }
  464.             if ((i < 49) && (domain_name[i] != NULL))
  465.             {
  466.                 (void) strncpy ((char *) &(tmppkt->B_fill2[8]), domain_abbrev[i], 8);
  467.             }
  468.         }
  469.         else
  470.         {
  471.             tmppkt->year = tm1->tm_year;
  472.             tmppkt->month = tm1->tm_mon;
  473.             tmppkt->day = tm1->tm_mday;
  474.             tmppkt->hour = tm1->tm_hour;
  475.             tmppkt->minute = tm1->tm_min;
  476.             tmppkt->second = tm1->tm_sec;
  477.             tmppkt->rate = 0;
  478.         }
  479.  
  480.         (void) fwrite ((char *) tmppkt, sizeof (struct _pkthdr), 1, fp);
  481.  
  482.         free (tmppkt);
  483.         (void) fwrite ("\0\0", 2, 1, fp);
  484.         (void) fclose (fp);
  485.     }
  486.     else
  487.     {
  488.         if ((fp = fopen (fname, rb_plus)) == NULL)
  489.         {
  490.             (void) got_error (MSG_TXT (M_OPEN_MSG), fname);
  491.             return (1);
  492.         }
  493.         tmppkt = (struct _pkthdr *) calloc (1, sizeof (struct _pkthdr));
  494.  
  495.         if (tmppkt == NULL)
  496.         {
  497.             status_line (MSG_TXT (M_MEM_ERROR));
  498.             return (1);
  499.         }
  500.         if (fread (tmppkt, 1, sizeof (struct _pkthdr), fp) < sizeof (struct _pkthdr))
  501.         {
  502.             (void) got_error (MSG_TXT (M_READ_MSG), fname);
  503.             free (tmppkt);
  504.             (void) fclose (fp);
  505.             return (1);
  506.         }
  507.  
  508.         if (n_getpassword (&called_addr) > 0)
  509.         {
  510.             if (remote_password != NULL)
  511.             {
  512.                 (void) strupr (remote_password);
  513.                 (void) strncpy ((char *) (tmppkt->password), remote_password, 8);
  514.             }
  515.         }
  516.  
  517.         /* Make sure the zone info is in there */
  518.  
  519.         tmppkt->orig_node = (int) alias[assumed].Node;
  520.         tmppkt->orig_net = (int) alias[assumed].Net;
  521.         tmppkt->orig_zone = (int) alias[assumed].Zone;
  522.         tmppkt->dest_zone = called_addr.Zone;
  523.  
  524.         if ((called_addr.Domain != NULL) &&
  525.             (called_addr.Domain != alias[assumed].Domain) &&
  526.             (my_addr.Domain != NULL))
  527.         {
  528.             /* Make it a type 2.2 packet instead */
  529.  
  530.             tmppkt->year = alias[assumed].Point;
  531.             tmppkt->month = called_addr.Point;
  532.             tmppkt->day = 0;
  533.             tmppkt->hour = 0;
  534.             tmppkt->minute = 0;
  535.             tmppkt->second = 0;
  536.             tmppkt->rate = 2;
  537.             if (alias[assumed].Domain != NULL)
  538.             {
  539.                 for (i = 0; domain_name[i] != NULL; i++)
  540.                 {
  541.                     if (domain_name[i] == alias[assumed].Domain)
  542.                     {
  543.                         break;
  544.                     }
  545.                 }
  546.                 if (i < 49)
  547.                 {
  548.                     (void) strncpy ((char *) tmppkt->B_fill2, domain_abbrev[i], 8);
  549.                 }
  550.             }
  551.             for (i = 0; domain_name[i] != NULL; i++)
  552.             {
  553.                 if (domain_name[i] == called_addr.Domain)
  554.                 {
  555.                     break;
  556.                 }
  557.             }
  558.             if (i < 49)
  559.             {
  560.                 (void) strncpy ((char *) &(tmppkt->B_fill2[8]), domain_abbrev[i], 8);
  561.             }
  562.         }
  563.  
  564.         (void) fseek (fp, 0L, SEEK_SET);
  565.         (void) fwrite (tmppkt, 1, sizeof (struct _pkthdr), fp);
  566.  
  567.         (void) fclose (fp);
  568.         free (tmppkt);
  569.     }
  570.  
  571.     net_problems = (no_sealink) ? Telink_Send_File (fname, s) : SEAlink_Send_File (fname, s);
  572.  
  573.     if (net_problems != 0)
  574.     {
  575.         if (c == NUM_FLAGS)
  576.             (void) unlink (fname);
  577.         return (net_problems);
  578.     }
  579.  
  580.     /* Delete the sent packet */
  581.     (void) unlink (fname);
  582.  
  583.     /*--------------------------------------------------------------------*/
  584.     /* Send files listed in ?LO files (attached files)                    */
  585.     /*--------------------------------------------------------------------*/
  586.  
  587.     *ext_flags = 'F';
  588.     status_line (" %s %s", MSG_TXT (M_OUTBOUND), MSG_TXT (M_FILE_ATTACHES));
  589.  
  590.     if (!do_FLOfile (ext_flags, FTSC_callback))
  591.         return FALSE;
  592.  
  593.     /*--------------------------------------------------------------------*/
  594.     /* Send our File requests to other system if it's a WaZOO             */
  595.     /*--------------------------------------------------------------------*/
  596.  
  597.     if (requests_ok && remote_capabilities)
  598.     {
  599.         (void) sprintf (fname, "%s%s.REQ", HoldName, Hex_Addr_Str (&called_addr));
  600.         if (!stat (fname, &buf))
  601.         {
  602.             if (!(((unsigned) remote_capabilities) & WZ_FREQ))
  603.                 status_line (MSG_TXT (M_FREQ_DECLINED));
  604.             else
  605.             {
  606.                 status_line (MSG_TXT (M_MAKING_FREQ));
  607.                 if (FTSC_callback (fname))
  608.                     (void) unlink (fname);
  609.             }
  610.         }
  611.     }
  612.  
  613.     /*--------------------------------------------------------------------*/
  614.     /* Process WaZOO file requests from other system                      */
  615.     /*--------------------------------------------------------------------*/
  616.  
  617.     j = respond_to_file_requests (j, FTSC_callback, FTSC_time);
  618.  
  619.     /* Now close out the file attaches */
  620.     sent_mail = 1;
  621.     *sptr = 0;
  622.     status_line (" %s %s %s", MSG_TXT (M_END_OF), MSG_TXT (M_OUTBOUND), MSG_TXT (M_FILE_ATTACHES));
  623.     (void) Batch_Send (NULL);
  624.     return TRUE;
  625. }
  626.  
  627. static int LOCALFUNC 
  628. FTSC_recvmail (int outbound_session)
  629. {
  630.     char fname[80];
  631.     char fname1[80];
  632.     char fname2[80];
  633.     struct _pkthdr tmppkt;
  634.     FILE *fp, *fp1;
  635.     int done;
  636.     int i = 0;
  637.     int j;
  638.     int logit = TRUE;
  639.     char *starting_inbound;
  640.  
  641.     status_line (MSG_TXT (M_RECV_MAIL));
  642.  
  643.     if (!CARRIER)
  644.     {
  645.         status_line (MSG_TXT (M_NO_CARRIER));
  646.         CLEAR_INBOUND ();
  647.         return (1);
  648.     }
  649.  
  650.     XON_DISABLE ();
  651.  
  652.     done = 0;
  653.  
  654.     /* If we don't want to pickup stuff */
  655.  
  656.     if (no_pickup)
  657.     {
  658.         status_line (MSG_TXT (M_NO_PICKUP));
  659.         SENDBYTE (CAN);
  660.     }
  661.     else
  662.     {
  663.         status_line (" %s %s", MSG_TXT (M_INBOUND), MSG_TXT (M_MAIL_PACKET));
  664.  
  665.         /* Invent a dummy name for the packet */
  666.  
  667.         invent_pkt_name (fname1);
  668.  
  669.         /* Receive the packet with special netmail protocol */
  670.  
  671.         CLEAR_INBOUND ();
  672.  
  673.         starting_inbound = CURRENT.sc_Inbound;
  674.  
  675.         if (Xmodem_Receive_File (CURRENT.sc_Inbound, fname1) == 0)
  676.         {
  677.             got_packet = 1;
  678.         }
  679.         (void) sprintf (fname, "%s%s", starting_inbound, fname1);
  680.  
  681.         /* Check the password if there is one */
  682.  
  683.         if ((!remote_capabilities) && (!outbound_session))
  684.             i = n_getpassword (&remote_addr);
  685.  
  686.         if (i < 0)
  687.         {
  688.             status_line (MSG_TXT (M_NUISANCE_CALLER));
  689.             LOWER_DTR ();        /* Hang up right now      */
  690.             goto bad_caller;
  691.         }
  692.  
  693.         if (i != 0)
  694.         {
  695.             if (remote_password != NULL)
  696.             {
  697.                 got_packet = 0;
  698.                 if ((fp = fopen (fname, rb_plus)) == NULL)
  699.                 {
  700.                     (void) got_error (MSG_TXT (M_OPEN_MSG), fname);
  701.                     status_line (MSG_TXT (M_PWD_ERR_ASSUMED));
  702.                     return (1);
  703.                 }
  704.                 if (fread (&tmppkt, 1, sizeof (struct _pkthdr), fp) < sizeof (struct _pkthdr))
  705.                 {
  706.                     (void) got_error (MSG_TXT (M_OPEN_MSG), fname);
  707.                     status_line (MSG_TXT (M_PWD_ERR_ASSUMED));
  708.                     (void) fclose (fp);
  709.                     return (1);
  710.                 }
  711.                 (void) fclose (fp);
  712.                 if (n_password ((char *) (tmppkt.password), remote_password, &logit))
  713.                 {
  714. bad_caller:
  715.                     (void) strcpy (fname1, fname);
  716.                     j = (int) strlen (fname) - 3;
  717.                     (void) strcpy (&(fname[j]), "Bad");
  718.                     if (rename (fname1, fname))
  719.                     {
  720.                         status_line (MSG_TXT (M_CANT_RENAME_MAIL), fname1);
  721.                     }
  722.                     else
  723.                     {
  724.                         status_line (MSG_TXT (M_MAIL_PACKET_RENAMED), fname);
  725.                     }
  726.                     return (1);
  727.                 }
  728.             }
  729.             got_packet = 1;
  730.         }
  731.   /*
  732.    *  See if things changed after the fact. If so, we want to move
  733.    *  the mail packet from the non-secured directory into the
  734.    *  secured one. This is slightly tricky. Start with a simple rename
  735.    *  and if that doesn't work (it might not if we're spanning drives)
  736.    *  do a simple copy/unlink.
  737.    *
  738.    *  Steal resources such as 'done' and 'Secbuf' wherever that makes sense.
  739.    */
  740.  
  741.         if (strcmp (starting_inbound, CURRENT.sc_Inbound) != 0)
  742.         {
  743.             (void) strcpy (fname2, CURRENT.sc_Inbound);
  744.             (void) strcat (fname2, fname1);
  745.  
  746.             /*  Try the easy case first. A straight rename. */
  747.  
  748.             done = 1;
  749.  
  750.             if (rename (fname2, fname))
  751.             {
  752.  
  753.      /*     If we get here, the straight rename didn't work. Let's
  754.       *     do a copy. Use Secbuf since while we are here, we're
  755.       *     not doing any file transfers.
  756.       */
  757.                 done = 0;        /* default is failure till files are open */
  758.  
  759.                 if ((fp = fopen (fname, rb_plus)) == NULL)
  760.                 {
  761.                     (void) got_error (MSG_TXT (M_OPEN_MSG), fname);
  762.                 }
  763.                 else if ((fp1 = fopen (fname2, write_binary)) == NULL)
  764.                 {
  765.                     (void) got_error (MSG_TXT (M_OPEN_MSG), fname2);
  766.                 }
  767.                 else
  768.                 {
  769.                     /* Here both packets are open */
  770.                     /* Steal Secbuf because nobody's using it now */
  771.  
  772.                     done = 1;    /* default is success now */
  773.  
  774.                     while ((j = fread (Secbuf, 1, WAZOOMAX, fp)) > 0)
  775.                     {
  776.                         if (fwrite (Secbuf, j, 1, fp1) != 1)
  777.                         {
  778.                             (void) got_error (MSG_TXT (M_WRITE_MSG), fname2);
  779.                             done = 0;    /* only possible failure = write err */
  780.                             break;
  781.                         }
  782.                     }
  783.                     (void) fclose (fp1);
  784.  
  785.                     if (done == 0)    /* Figure out which file to delete */
  786.                         (void) unlink (fname2);
  787.                     else
  788.                         (void) unlink (fname);
  789.                 }
  790.             }
  791.             if (done == 0)
  792.                 status_line (MSG_TXT (M_CANT_RENAME_MAIL), fname);
  793.             else
  794.                 status_line (MSG_TXT (M_MAIL_PACKET_RENAMED), fname2);
  795.         }
  796.  
  797.   /*
  798.    * If this was an inbound session, we need to set up the
  799.    * node flags for the node.
  800.    */
  801.         got_mail = got_packet;
  802.         if (!outbound_session)
  803.         {
  804.             if (flag_file (TEST_AND_SET, &remote_addr, 1))
  805.                 return (1);
  806.             called_addr = remote_addr;
  807.         }
  808.  
  809.         done = 0;
  810.  
  811.         /* Now receive the files if possible */
  812.  
  813.         status_line (" %s %s", MSG_TXT (M_INBOUND), MSG_TXT (M_FILE_ATTACHES));
  814.         done = Batch_Receive (CURRENT.sc_Inbound);
  815.     }
  816.  
  817.     status_line (" %s %s %s", MSG_TXT (M_END_OF), MSG_TXT (M_INBOUND), MSG_TXT (M_FILE_ATTACHES));
  818.     CLEAR_INBOUND ();
  819.     return (done);
  820. }
  821.  
  822. static int 
  823. FTSC_callback (char *sptr)
  824. {
  825.     net_problems = Batch_Send (sptr);
  826.     if (net_problems != 0)
  827.     {
  828.         net_problems = 1;
  829.         return FALSE;
  830.     }
  831.     return TRUE;
  832. }
  833.  
  834. static int 
  835. FTSC_time (long filesize)
  836. {
  837.     long ltemp;
  838.  
  839.     ltemp = filesize * 10L / cur_baud.rate_value * 100L / 94L;
  840.     return (ltemp < 20L) ? 20 : (int) ltemp;
  841. }
  842.